import $ from 'zepto';
import Vue from 'vue';
import Ajax from 'static/modules/ajax.js';

var app = new Vue({
	el: '#app',
	data() {
		return {
			placeText: '输入金额',
			amount: '',
			evaluateShow: false,
			authShow: false
		}
	},
	methods: {
		showKeyBoard() {
			//键盘弹出的同时，传入输入框对象
			this.$refs.virtualKeyBoard.$emit('getInputVm', this.$refs.virtualInput);
		},
		submit(amount){
			var that = this;
			if(amount){
				//获取 payinfo
				Ajax.post('/cx/cashier/h5/payment',{pmi:pmi,amount:amount})
				.then((res)=>{
					OpenMidas.init(midas_env);
					//唤起米大师支付
					OpenMidas.pay(res.pay_info, function(resultCode,innerCode,resultMsg){
						if(resultCode == 0){
							that.$wii.toast.show({
				            	text: '支付成功！',
				            	type: 'success'
					        });
					        setTimeout(()=>{
					        	location.href = redirect_url;
					        },2000);
						}else{
							that.$wii.toast.show({
				            	text: resultMsg,
				            	type: 'warn'
					        });
						}
					});
				});
			}else{
				that.$wii.toast.show({
	            	text: '金额必须输入',
	            	type: 'warn'
		        });
			}
		},
		popupHandler(res){
			console.log(res);
		},
		showEvaluate(evt){
			if(isAuth){
				this.evaluateShow = true;
			}else{
				this.authShow = true;
			}
		},
		submitEvaluate(evt){
			var form = $(evt.target).closest('form');
			var data = form.serializeArray();
			Ajax.post('/cx/cashier/h5/payment',data)
			.then((res)=>{
				console.log(res);
				this.evaluateShow = false;
			})
			console.log('submitEvaluate');
		},
		sendVcode(){
			console.log('发送验证码');
		},
		submitAuth(evt){
			var form = $(evt.target).closest('form');
			var data = form.serializeArray();
			Ajax.post('/cx/cashier/h5/payment',data)
			.then((res)=>{
				console.log(res);
				this.authShow = false;
			})
			console.log('submitAuth');
		}
	},
	mounted() {
		console.log(Ajax);
		if ('addEventListener' in document) {
			// document.addEventListener('DOMContentLoaded', function(){
			//     FastClick.attach(document.body);
			// }, false);
		}
		//保证子组件实例化完成之后将virtualInput的实例传给virtualKeyBoard
		if(this.$refs.virtualKeyBoard){
			this.$refs.virtualKeyBoard.$emit('getInputVm', this.$refs.virtualInput);
		}
	}
});